/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN 50

using namespace std;

vector <int> to[MAXN], p;
queue <int> bf;
int n, m, f[MAXN][MAXN], q;
bool qc[MAXN];

inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}

void bfs(int a, int b) {
	memset(qc, 0, sizeof(qc));
	bf.push(a);
	p.push_back(a); 
	p.push_back(b);
	qc[a] = 1;
	qc[b] = 1;
	while(!bf.empty()) {
		int x = bf.front();
		bf.pop();
		for(int i = 0; i < to[x].size(); i++) {
			int y = to[x][i];
			if(f[y][b] == f[x][b] - 1 && y != b && !qc[y]) {
				qc[y] = 1;
				p.push_back(y);
				bf.push(y); 
			}
		}
	}
	sort(p.begin(), p.end());
	for(int i = 0; i < p.size(); i++) {
		printf("%d ",p[i]);
	}
	printf("\n");
	p.clear();
}

int main() {
#ifndef LOCAL
	freopen("geo.in", "r", stdin);
	freopen("geo.out", "w", stdout);
#else 
	freopen("in.txt", "r", stdin);
#endif
	n = read();
	m = read();
	
	memset(f, 127 / 2, sizeof(f));
	
	for(int i = 0; i < m; i++) {
		int x = read();
		int y = read();
		to[x].push_back(y);
		to[y].push_back(x);
		f[x][y] = f[y][x] = 1;
	}
	
	for(int i = 1; i <= n; i++)
		f[i][i] = 0;
	
	for(int k = 1; k <= n; k++) {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
			}
		}
	}
	
//	for(itn i )
	
	q = read();
	
	while(q--) {
		int x = read();
		int y = read();
		bfs(x, y);
	}
	
	return 0;
}

